***********************************************************************************************
***
***	INTERTEMPORAL EVIDENCE ON THE STRATEGY OF POPULISM IN THE US (Gennaro, Lecce, Morelli)
***	Replication Package
***  
*** Appendix - Table A18-A19
***
***********************************************************************************************



clear
est clear 

* Indicate location of the replication package here
cd "/Replication Package"


**********************************************
* Upload Data                            *****
**********************************************

use "3_data/for_analysis/congress_election_both.dta", clear

replace name = trim(name)

preserve

	import delimited "3_data/processed/tfidf_pop_by_topic.csv", colrange(1) numericcols(1) clear 
	drop v1
	
	* fix names match with unicode errors & co
	replace name = "Nydia Velázquez" if name == "Nydia VelÃ¡zquez"
	replace name = `"Jesús "Chuy" García"' if name == `"JesÃºs "Chuy" GarcÃ­a"'
	replace name = "Ann Wagner" if name == "Ann Wegner"
	replace name = "Vicente González" if name == "Vicente GonzÃ¡lez"
	replace name = "Ben Ray Luján" if name == "Ben Ray LujÃ¡n"
	replace name = "Adair Ford Boroughs" if name =="Adair Ford Boroughs -- 2020 -- South Carolina"
	replace name = "Antonio Sabàto Jr." if name == "Antonio SabÃ to Jr."
	replace name = "Andy Briggs" if name == "Andy Biggs"
	replace name = "Charlotte Bergman" if name == "Charlotte Bergmann"
	replace name = "Dean Phillips" if name == "Dean Philips"
	replace name = "G. K. Butterfield" if name == "G.K. Buttefield"
	replace name = "Jackie Walorski" if name == "Jackie Walorwski"
	replace name = "Jackie Walorski" if name == "Jackie Walorwski"
	replace name = "Jeannine Lake" if name == "Jeannine Lee Lake"
	replace name = "Jesús García" if name == "Jesus Garcia"
	replace name = "John Moolenaar" if name == "John Moolenar"
	replace name = "Juan Hidalgo Jr." if name == "Juan Hidalgo"
	replace name = "Kevin McCarthy" if name == "Kevin McCharty"
	replace name = "Madaleine Dean" if name == "Madeleine Dean"
	replace name = "Pramila Jayapal" if name == "Pramila Jaypal"
	replace name = "Raja Krishnamoorthi" if name == "Raja Krishnamoorth"
	replace name = "T.J. Cox" if name == "TJ Cox"
	replace name = "Charlotte Bergmann" if name == "Charlotte Bergman"
	replace name = "Eric Swalwell" if name == "Erik Swalwell"
	replace name = "Chuck Fleischmann" if name == "Charles Fleischmann"
	replace name = "Vicente González" if name == "Vicente Gonzalez"
	replace name = "Gerry Connolly" if name == "Gerald Connolly"
	replace name = "Joe Morelle" if name == "Joseph Morelle"
	replace name = "Mark Green" if name == "Mark Greene"
	replace name = "Mike Doyle" if name == "Michael Doyle"
	replace name = "Mike Simpson" if name == "Michael Simpson"
	replace name = "Mike Turner" if name == "Michael Turner"
	replace name = "Rob Wittman" if name == "Robert Wittmann"
	replace name = "Ron Wright" if name == "Ronald Wright"
	replace name = "Tabitha Johnson-Green" if name == "Tabitha Johnson-Greene"
	replace name = "Terri Sewell" if name == "Terry Sewell"
	replace name = "Tony Cárdenas" if name == "Tony Cardenas"
	replace name = "Tracy Mitrano" if name == "Tracy Miltrano"
	replace name = "Al Lawson" if name == "Alfred Lawson"
	replace name = "Andy Harris" if name == "Andrew Harris"
	replace name = "Cristina Osmeña" if name == "Cristina OsmeÃ±a"
	replace name = "Dan Crenshaw" if name == "Daniel Crenshow"
	replace name = "Tony Cárdenas" if name == "Tony CÃ¡rdenas"

	replace name = "Louie Gohmert" if name == "Louis Gohmert"
	replace name = "Susie Lee" if name == "Susie lee"
	replace state_name = "New Jersey" if name == "James Tosone"
	replace state_name = "Missouri" if name == "Mark Bliss"
	replace state_name = "Oregon" if name == "Mark Roberts"
	replace state_name = "New Jersey" if name == "Robert Crook"
	replace state_name = "Idaho" if name == "Natalie Fleming"	
	replace state_name = "Mississippi" if name == "Troy Ray"

	tempfile temp
	save `temp'
	
restore

replace  name = "Antonio Delgado" if name == "Antonio Delgado_ny"
replace  name = "Antonio Delgado" if name == "Antonio Delgado_CA"

merge 1:1 name state_name election_year using `temp'
tab _m if pop_dim2 !=.
drop _m /* unmatched candidates have missing populism values - no text */


**********************************************
* Adjust variables.                      *****
**********************************************

foreach var in pop_econ pop_econ_ext pop_other{
	cap egen `var'_s = std(`var')
	}


**********************************************
* Sample selection.                      *****
**********************************************

keep if uncont==0 & indep==0
global controls "female i.age_cat_num i.ethnicity2 i.educ_cat len_words i.election_year"


**********************************************************
* A18: Populism excluding economic topics                 *****
**********************************************************

est clear 

local outcomes "pop_other_s pop_econ_ext_s pop_econ_s"
foreach var in `outcomes'{

	di "`var'"
	eststo: areg `var' i.outsider_correct $controls , a(state) cluster(district)
	eststo: areg `var' i.outsider_correct##c.econ $controls , a(state) cluster(district)
	eststo: areg `var' i.outsider_correct##i.competitivedistricts##c.econ $controls , a(state) cluster(district)
}


esttab _all using "4_results/tables/tabA18.tex", f label replace booktabs alignment(D{.}{.}{-1}) keep(1.outsider_correct 1.competitivedistricts econ 1.outsider_correct#1.competitivedistricts 1.outsider_correct#c.econ 1.competitivedistricts#c.econ  1.outsider_correct#1.competitivedistricts#c.econ) s(N r2, fmt(0 2) label("Observations" "R-squared")) nomtitles star(* 0.10 ** 0.05 *** 0.01) r2 b(3) se(3) brac nonotes 




**********************************************************
* A19 : Attention to   economic topics                     
**********************************************************

est clear 

local outcomes "len_words_pop_econ len_words_pop_econ_ext"
foreach var in `outcomes'{
	
	di "`var'"
	cap gen `var'_n = `var' / len_words  // Calculate attention relative to total doc length
}

foreach var in `outcomes'{

	di "`var'"
	eststo: areg `var'_n i.outsider_correct $controls , a(state) cluster(district)
	eststo: areg `var'_n i.outsider_correct##c.econ $controls , a(state) cluster(district)
	eststo: areg `var'_n i.outsider_correct##i.competitivedistricts##c.econ $controls , a(state) cluster(district)

}

esttab _all using "4_results/tables/tabA19.tex", f label replace booktabs alignment(D{.}{.}{-1})  keep(1.outsider_correct 1.competitivedistricts econ 1.outsider_correct#1.competitivedistricts 1.outsider_correct#c.econ 1.competitivedistricts#c.econ  1.outsider_correct#1.competitivedistricts#c.econ) s(N r2, fmt(0 2) label("Observations" "R-squared")) nomtitles star(* 0.10 ** 0.05 *** 0.01) r2 b(3) se(3) brac nonotes 





